home *** CD-ROM | disk | FTP | other *** search
- Path: uuneo.neosoft.com!usenet
- From: Wmatthew@lan-aces.com (W. Matthews)
- Newsgroups: comp.lang.c++
- Subject: Re: Pointer to non-static function
- Date: 11 Mar 1996 15:33:20 GMT
- Organization: LAN-ACES, Inc.
- Message-ID: <4i1h40$b7i@uuneo.neosoft.com>
- References: <4hnsfs$cp2@nntp.ucs.ubc.ca>
- NNTP-Posting-Host: 198.65.178.8
- X-Newsreader: WinVN 0.92.5
-
- In article <4hnsfs$cp2@nntp.ucs.ubc.ca>, jamesdf@unixg.ubc.ca (James Fairweather) says:
- >
- >I am attempting to make some code I've written more elegant by using a
- >pointer to a function. Here's how I declare the pointer:
- >
- > double (*f)(double);
- >
- >Now I'd like to make f point to one of two functions, one declared as:
- >
- > double CFunction::Calculate(double);
- >
- >and the other as:
- >
- > double CEquation::Calculate(double);
- >
- >Neither are static, and CEquation and CFunction are not related by
- >inheritance. Nor can they be, since CEquation contains a list of
- >CFunctions.
- >
- >At compile time, the compiler issues an error, "cannot convert from
- >double (CFunction::*)(double) to double (__cdecl *)(double)" and
- >"cannot convert from double (CEquation::*)(double) to double (__cdecl
- >*)(double)".
- >
- >This looks suspiciously like a typecasting problem to me. I'm
- >wondering if what I'm attempting to do is possible, and if so, how to
- >do it. What is the correct way to do the typecast, if that is the
- >problem? Any help is much appreciated.
- >
- > James
-
- What are you doing on the storage line?
- f = &Calculate(x) or just f = &Calculate?
- (Be warned neither of these may work properly-my func pntr info a little
- rust, say like the TITANIC)
- ______________________________________________
- |Wyatt Matthews: Tech Support Department |
- |WMATTHEW@LAN-ACES.COM -Internet- |
- |WMATTHEW.MHS@LAN-ACES -MHS- |
- |LAN-ACES Tech Support (713)890-9786 |
- |LAN-ACES BBS (713)890-9790 |
- |LAN-ACES Fax (713)890-9731 |
- |LAN-ACES Sales (713)890-9787 |
- ______________________________________________
-